package svgedit.gui.commands;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;


/**
 * Just like an SVGGroup this Command can contain more commands,
 * for example to use when moving multiple shapes at once, or moving one shape,
 * to combine all the little moves (pixels) as one big command
 * @author SARJ
 *
 */
public class CompositeCommand implements Command, Iterable<Command>
{
	public List<Command> commands;
	
	/**
	 * Constructs the composite command
	 * Prepares its array list
	 */
	public CompositeCommand()
	{
		this.commands = new ArrayList<Command>();
	}
	
	/**
	 * Overloaded constructor to take it an array list of commands
	 * @param commands
	 */
	public CompositeCommand(Command[] commands)
	{
		this.commands = Arrays.asList(commands);
	}
	
	
	@Override
	public Iterator<Command> iterator()
	{
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public void executeUndo()
	{
		for (Command command : commands)
			command.executeUndo();
		
	}

	@Override
	public void executeRedo()
	{
		for (Command command : commands)
			command.executeRedo();
		
	}

	/**
	 * Add a command to the list of commands this composite command handles
	 * @param command The command to add the the list
	 */
	public void addCommand(Command command)
	{
		commands.add(command);		
	}
	
	/**
	 * Retrieves the number of commands in the composite command
	 * @return The number of commands
	 */
	public int getCommandsCount()
	{
		return commands.size();
		
	}

}
